import java.util.Arrays;

public class Test {
    /**
     *数组作业
     * @return
     */
    //冒泡排序
    //1,3,5,8,9,7
    //0,1,2,3,4,5
    public static void bubblesort(int [] array){
        for (int i = 0; i < array.length-1; i++) {
                boolean flg= false;
            for (int j = 0; j <array.length-1-i; j++) {
                if(array[j]>array[j+1]){
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                    flg= true;
                }
            }
            if(!flg){
                break;
            }
        }
    }
    public static void main(String[] args) {
        int [] rray = {1,8,42,97,9,3};
        System.out.print("交换前：");
        System.out.println(Arrays.toString(rray));
        bubblesort(rray);
        System.out.print("交换后：");
        System.out.println(Arrays.toString(rray));
    }


    //给定一个有序整型数组, 实现二分查找
    public static  int binarysearch (int [] num,int key){
        int index=Arrays.binarySearch(num,key);
        return index;
    }
    public static void main3(String[] args) {
        int [] array = {1,5,3,8,12,6};
        Arrays.sort(array);  //1,3,5,6,8,12
        int ret= binarysearch(array,8);
        System.out.println(ret);
    }
    //实现一个方法 transform, 以数组为参数, 循环将数组中的每个元素 乘以 2 , 并设置到对应的数组元素上. 例如 原数组为 {1, 2, 3}, 修改之后为 {2, 4, 6}
    public static void Transform (int [] transform ){
        System.out.print("修改后数组:");
        System.out.print(" [");
        for (int i = 0; i < transform.length; i++) {
            System.out.print(transform[i] *2+" ");
            if(i!=transform.length-1){
                System.out.print(",");
            }
        }
        System.out.println("]");
    }
    public static void main2(String[] args) {
        int [] array ={1,2,3};
        System.out.print("修改前数组：");
        System.out.println(Arrays.toString(array));
          Transform(array);

    }
    public static int [] add (){
     int a = 1;
     int b = 2;
     int [] ret = new int[]{a,b};
     return ret ;
    }
    public static void main1(String[] args) {
        int [] array = add();
        String sum = Arrays.toString(array);
        System.out.println(sum);

    }
}
